<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Controller;
use DB;

class UserController extends Controller
{

    public function getIndex()
    {
		$res = DB::select('select * from users');
		
		$num = DB::table('users')->count();
		$num = DB::table('article')->sum('reply_num');
		dd($num);

		// 调用自定义方法
		test();

        // return view('/showtable', ['res' => $res]);
    }

    public function getUpdate($id)
    {
		echo "用户id" . $id;
    }

    public function getDelete($id)
    {
        $res = DB::delete("delete from users where id = " . $id);

        if ($res) {
            // 成功

        } else {
            // 失败
        }
    }

    public function getAdd()
    {
        return view('/addadmin');
    }

    public function postInsert(Request $request)
    {
		// 判断是否上传了文件
        if ($request->hasFile('picture')) {
            //接收上传文件的后缀名
            $ext = $request->file('picture')->getClientOriginalExtension();

            // 随机一个文件名
            $filename = date('YmdHis') . "." . $ext; 

            // 将上传的文件存储到 ./uploads文件夹中，并接收文件信息
            $res = $request->file('picture')->move('./uploads/', $filename);
        }

    }

}
